#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "buttons.h"
#include "backlight.h"

stButton_t butPage;
stButton_t butUp;
stButton_t butDn;


void BUTTONS_init( stButton_t *b )
{
	b->state = STATE_none;
	b->time = 0;
}


void BUTTONS_check( stButton_t *b, uint8_t input )
{
	if( input == 0 ) {
		if( b->time < 0xff ) b->time++;
		if( b->time == MIN_DEBOUNCE ) {
			//kick the backlight into action
			BACKLIGHT_Kick();
			b->state = STATE_pressed;
		}
	}
	else {	//input has gone high (button released)
		if( b->state == STATE_pressed ) {
			b->state = STATE_released;
		}
		else {
			b->time = 0;
			b->state = STATE_none;
		}
	}
}
